﻿namespace homewizard
{
    using ATPLDAL;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.IO;
    using System.Runtime.CompilerServices;

    public class login
    {

        #region [Feedback,Ideas,Tasks,Tips,verifyPromoCode]

        public DataSet checklogin()
        {
            DataSet set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[4];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = 1;
                commandParameters[1] = new SqlParameter("@User_Name", SqlDbType.VarChar, 100);
                commandParameters[1].Value = this.User_Name;
                commandParameters[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                commandParameters[2].Value = this.Password;
                commandParameters[3] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[3].Direction = ParameterDirection.Output;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_User", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public DataSet ideadata()
        {
            DataSet set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[8];
                commandParameters[0] = new SqlParameter("@dwell_priority_kl_loc", SqlDbType.NVarChar);
                commandParameters[0].Value = this.dwell_priority_kl_loc;
                commandParameters[1] = new SqlParameter("@feature_string", SqlDbType.NVarChar);
                commandParameters[1].Value = this.feature_string;
                commandParameters[2] = new SqlParameter("@ps_goal_string", SqlDbType.NVarChar);
                commandParameters[2].Value = this.ps_goal_string;
                commandParameters[3] = new SqlParameter("@turn_offs", SqlDbType.NVarChar);
                commandParameters[3].Value = this.turn_offs;
                commandParameters[4] = new SqlParameter("@startmonth", SqlDbType.Int);
                commandParameters[4].Value = this.startmonth;
                commandParameters[5] = new SqlParameter("@startyear", SqlDbType.Int);
                commandParameters[5].Value = this.startyear;
                commandParameters[6] = new SqlParameter("@requestedmonth", SqlDbType.Int);
                commandParameters[6].Value = this.requestedmonth;
                commandParameters[7] = new SqlParameter("@requestedyear", SqlDbType.Int);
                commandParameters[7].Value = this.requestedyear;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_Ideas", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public string InsertFeedBack()
        {
            string str;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[3];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = this.operation;
                commandParameters[1] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[1].Direction = ParameterDirection.Output;
                commandParameters[2] = new SqlParameter("@FeedBack", SqlDbType.NVarChar);
                commandParameters[2].Value = this.feedback;
                SqlHelper.ExecuteNonQuery(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_User", commandParameters);
                if (Convert.ToInt32(commandParameters[1].Value) == 1)
                {
                    return "success";
                }
                str = "Fail";
            }
            catch (Exception)
            {
                throw;
            }
            return str;
        }

        public DataSet prechecklogin()
        {
            DataSet set = new DataSet();
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[4];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = 11;
                commandParameters[1] = new SqlParameter("@User_Name", SqlDbType.VarChar, 100);
                commandParameters[1].Value = this.User_Name;
                commandParameters[2] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                commandParameters[2].Value = this.Password;
                commandParameters[3] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[3].Direction = ParameterDirection.Output;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_User", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public string promochecklogin()
        {
            string str = "";
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[3];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = 2;
                commandParameters[1] = new SqlParameter("@sponsor", SqlDbType.VarChar, 100);
                commandParameters[1].Value = this.promocode;
                commandParameters[2] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[2].Direction = ParameterDirection.Output;
                SqlHelper.ExecuteReader(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_User", commandParameters);
                if (Convert.ToInt32(commandParameters[2].Value) == 2)
                {
                    str = "success";
                }
                if (Convert.ToInt32(commandParameters[2].Value) == 3)
                {
                    str = "failed";
                }
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return str;
        }

        public DataSet promologin()
        {
            DataSet set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[3];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = 2;
                commandParameters[1] = new SqlParameter("@sponsor", SqlDbType.VarChar, 100);
                commandParameters[1].Value = this.promocode;
                commandParameters[2] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[2].Direction = ParameterDirection.Output;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_User", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public DataSet task()
        {
            DataSet set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[8];
                commandParameters[0] = new SqlParameter("@dwell_priority_kl_loc", SqlDbType.NVarChar);
                commandParameters[0].Value = this.dwell_priority_kl_loc;
                commandParameters[1] = new SqlParameter("@feature_string", SqlDbType.NVarChar);
                commandParameters[1].Value = this.feature_string;
                commandParameters[2] = new SqlParameter("@ps_goal_string", SqlDbType.NVarChar);
                commandParameters[2].Value = this.ps_goal_string;
                commandParameters[3] = new SqlParameter("@turn_offs", SqlDbType.NVarChar);
                commandParameters[3].Value = this.turn_offs;
                commandParameters[4] = new SqlParameter("@startmonth", SqlDbType.Int);
                commandParameters[4].Value = this.startmonth;
                commandParameters[5] = new SqlParameter("@startyear", SqlDbType.Int);
                commandParameters[5].Value = this.startyear;
                commandParameters[6] = new SqlParameter("@requestedmonth", SqlDbType.Int);
                commandParameters[6].Value = this.requestedmonth;
                commandParameters[7] = new SqlParameter("@requestedyear", SqlDbType.Int);
                commandParameters[7].Value = this.requestedyear;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_Routinetask", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public DataSet tipdata()
        {
            DataSet set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[8];
                commandParameters[0] = new SqlParameter("@dwell_priority_kl_loc", SqlDbType.NVarChar);
                commandParameters[0].Value = this.dwell_priority_kl_loc;
                commandParameters[1] = new SqlParameter("@feature_string", SqlDbType.NVarChar);
                commandParameters[1].Value = this.feature_string;
                commandParameters[2] = new SqlParameter("@ps_goal_string", SqlDbType.NVarChar);
                commandParameters[2].Value = this.ps_goal_string;
                commandParameters[3] = new SqlParameter("@turn_offs", SqlDbType.NVarChar);
                commandParameters[3].Value = this.turn_offs;
                commandParameters[4] = new SqlParameter("@startmonth", SqlDbType.Int);
                commandParameters[4].Value = this.startmonth;
                commandParameters[5] = new SqlParameter("@startyear", SqlDbType.Int);
                commandParameters[5].Value = this.startyear;
                commandParameters[6] = new SqlParameter("@requestedmonth", SqlDbType.Int);
                commandParameters[6].Value = this.requestedmonth;
                commandParameters[7] = new SqlParameter("@requestedyear", SqlDbType.Int);
                commandParameters[7].Value = this.requestedyear;
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_Tips", commandParameters);
            }
            catch (Exception exception)
            {
                string path = @"C:\homewizard\Error.txt";
                File.WriteAllText(path, exception.ToString());
            }
            return set;
        }

        public string webserviceListInsert()
        {
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[5];
                commandParameters[0] = new SqlParameter("@op", SqlDbType.Int);
                commandParameters[0].Value = 1;
                commandParameters[1] = new SqlParameter("@WebServiceName", SqlDbType.VarChar);
                commandParameters[1].Value = this.WebServiceName;
                commandParameters[2] = new SqlParameter("@DataRequested", SqlDbType.VarChar);
                commandParameters[2].Value = this.DataForService;
                commandParameters[3] = new SqlParameter("@Result", SqlDbType.Int);
                commandParameters[3].Direction = ParameterDirection.Output;
                commandParameters[4] = new SqlParameter("@DataRecived", SqlDbType.VarChar);
                commandParameters[4].Value = this.DataRecived;
                SqlHelper.ExecuteNonQuery(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_WebserviceList", commandParameters);
            }
            catch (Exception)
            {
                throw;
            }
            return "success";
        }

        #endregion

        #region[Android App]
        public DataTable Initial_Setupdata()
         {
            DataTable set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[8];
                commandParameters[0] = new SqlParameter("@paramUserName", SqlDbType.NVarChar);
                commandParameters[0].Value = this.User_Name;
                commandParameters[1] = new SqlParameter("@paramPassword", SqlDbType.NVarChar);
                commandParameters[1].Value = this.Password;
                commandParameters[2] = new SqlParameter("@paramPromoCode", SqlDbType.NVarChar);
                if (!String.IsNullOrEmpty(this.promocode))
                {
                    commandParameters[2].Value = this.promocode;
                }
                else
                {
                    commandParameters[2].Value = DBNull.Value;
                }

                commandParameters[3] = new SqlParameter("@paramAppMoAlertWeek", SqlDbType.Int);
                commandParameters[3].Value = this.app_mo_alert_week;

                commandParameters[4] = new SqlParameter("@paramAppMoAlertDay", SqlDbType.Int);
                commandParameters[4].Value = this.app_mo_alert_day;


                commandParameters[5] = new SqlParameter("@paramAppMoAlertHour", SqlDbType.Int);
                commandParameters[5].Value = this.app_mo_alert_hour;

                commandParameters[6] = new SqlParameter("@paramAppMoAlertBadge", SqlDbType.Int);
                commandParameters[6].Value = this.app_mo_alert_badge;

                commandParameters[7] = new SqlParameter("@paramAppMoAlertPopup", SqlDbType.Int);
                commandParameters[7].Value = this.app_mo_alert_popup;

                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_App_Initial_Setup", commandParameters).Tables[0];
            }
            catch (Exception exception)
            {
                //string path = @"C:\homewizard\Error.txt";
                //File.WriteAllText(path, exception.ToString());
            }
            return set;
        }
        public DataTable App_Reopendata()
        {
            DataTable set = null;
            try
            {
                SqlParameter[] commandParameters = new SqlParameter[6];
                commandParameters[0] = new SqlParameter("@paramUserId", SqlDbType.NVarChar);
                commandParameters[0].Value = this.UserID;
                commandParameters[1] = new SqlParameter("@paramUserName", SqlDbType.NVarChar);
                commandParameters[1].Value = this.User_Name;
                commandParameters[2] = new SqlParameter("@paramPassword", SqlDbType.NVarChar);
                commandParameters[2].Value = this.Password;
                commandParameters[3] = new SqlParameter("@paramPromoCode", SqlDbType.NVarChar);
                commandParameters[3].Value = this.promocode;
                commandParameters[4] = new SqlParameter("@paramWelcomeImageChgTime", SqlDbType.NVarChar);
                
                if (!String.IsNullOrEmpty(this.WelcomeImageChgTime))
                {
                    commandParameters[4].Value = this.WelcomeImageChgTime;
                }
                else
                {
                    commandParameters[4].Value = DBNull.Value;
                }
                commandParameters[5] = new SqlParameter("@paramSponsorCchangeTime", SqlDbType.NVarChar);
                if (!String.IsNullOrEmpty(this.SponsorCchangeTime))
                {
                    commandParameters[5].Value = this.SponsorCchangeTime;
                }
                else
                {
                    commandParameters[5].Value = DBNull.Value;
                }
                set = SqlHelper.ExecuteDataset(Convert.ToString(ConfigurationManager.AppSettings["ConnectionString"]), CommandType.StoredProcedure, "sp_App_Reopen", commandParameters).Tables[0];
            }
            catch (Exception exception)
            {
                //string path = @"C:\homewizard\Error.txt";
               // File.WriteAllText(path, exception.ToString());
            }
            return set;
        }
        #endregion

        #region [Properties]

        public string art_code { get; set; }

        public string currenthome { get; set; }

        public string DataForService { get; set; }

        public string DataRecived { get; set; }

        public string dwell_priority_kl_loc { get; set; }

        public string feature_string { get; set; }

        public string feedback { get; set; }

        public string idea_code { get; set; }

        public int operation { get; set; }

        public string Password { get; set; }

        public string promocode { get; set; }

        public string ps_goal_string { get; set; }

        public string requestedmonth { get; set; }

        public string requestedyear { get; set; }

        public int Result { get; set; }

        public string startmonth { get; set; }

        public string startyear { get; set; }

        public string task_code { get; set; }

        public string tip_code { get; set; }

        public string turn_offs { get; set; }

        public string User_Name { get; set; }

        public string UserID { get; set; }

        public string WebServiceName { get; set; }

        public string SentFrom { get; set; }

        public string AppSetup { get; set; }

        public string WelcomeImageChgTime { get; set; }
        public string SponsorCchangeTime { get; set; }


        public string app_mo_alert_week { get; set; }
        public string app_mo_alert_day { get; set; }
        public string app_mo_alert_hour { get; set; }
        public string app_mo_alert_badge { get; set; }
        public string app_mo_alert_popup { get; set; }
      
        #endregion

    }
}

